package fachlogik;

import java.awt.Color;
import java.awt.Component;
import java.text.SimpleDateFormat;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import entities.Appointment;

public class TermineCellRenderer extends JLabel implements ListCellRenderer {

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		if (value != null) {
			setOpaque(true);
			Appointment a = (Appointment) value;
			SimpleDateFormat df = new SimpleDateFormat("HH:mm");
			if (a.getBegin() != null && a.getEnd() != null) {
				String beginn = df.format(a.getBegin());
				String ende = df.format(a.getEnd());
				this.setText(beginn + " - "  + ende + "      " + a.getName());
			}
			else
				this.setText(a.getName());
		}
		if (isSelected)
			setBackground(Color.LIGHT_GRAY);
		else
			setBackground(Color.white);

		return this;
	}
}